from google.appengine.ext import db
from Common.DuplicatedInstanceError import DuplicatedInstanceError
from Common.Validator import Validator

class Company(db.Model, Validator):
    CompanyName = db.StringProperty(required=True)
    
    _rules = {
        'CompanyName' : [Validator.name]
    }
    
    def put (self):
        # Make sure e-mails are unique for each user
        if (not self.is_saved()) and Company.get_by_key_name(self.CompanyName):
            raise DuplicatedInstanceError ('User.UserName', self.CompanyName)
 
        # call the parent method
        db.Model.put (self)
        
    def TransactionPut(self):
        db.run_in_transaction(self.put)
        
"""
owner = db.User(auto_current_user_add=True)
  created = db.DateTimeProperty(auto_now_add=True)
"""